package cn.bbs.ba.base;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.bbs.ba.html.ZPaiConstant;
import cn.bbs.ba.log.LogTrac;
import cn.bbs.ba.session.SessionFactory;

public class BAAction extends Action {
	protected UserInfo userInfo = null;
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.setHeader("Content-Type","text/html; charset=UTF-8");
		if (SessionFactory.getSessionDto(request) != null) {
			userInfo = (UserInfo)SessionFactory.getSessionDto(request).getMap();
		}
		else {
			return null;
		}
		return mapping.findForward("indexPage");
	}
	
	/**
	 * 得到IP地址
	 * @param request
	 * @return
	 */
	public String getRemortIp(HttpServletRequest request) {

		if (request.getHeader("x-forwarded-for") == null) {
			return request.getRemoteAddr();
		}
		return request.getHeader("x-forwarded-for").split(",")[0];
	}
	
	/**
	 * 取国际化值
	 * @param strPara
	 * @return
	 */
	public String getResouceDisplayAt(String strPara) {
		String language = ZPaiConstant.getLanguage();
		return ZPaiConstant.getResouceDisplayAt(strPara, language);
	}
	
	public void trac(String tracLog) {
		LogTrac.trace(tracLog);
	}
}
